package cn.echo.ecc.feign;

import cn.echo.ecc.domain.Login;
import cn.echo.ecc.enums.GlobalExceptionCode;
import cn.echo.ecc.result.JSONResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class LoginServiceFallbackFactory implements FallbackFactory<LoginService> {
    @Override
    public LoginService create(Throwable e) {
        e.printStackTrace();
        log.error("熔断触发，服务降级不可用，具体错误信息：{}",e.getMessage());
        return new LoginService() {
            @Override
            public JSONResult saveOrUpdate(Login login) {
                return JSONResult.error(GlobalExceptionCode.FAIL);
            }
        };
    }
}
